-
-
Notifications
You must be signed in to change notification settings - Fork 103
feat: server prompts #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
@yjacquin it's still a WIP, please look at the examples - do you like dsl like this (we have to handle multiple message on the output), and i see value to have support for erb templates for prompts (might be especial useful if you want to keep the in certain format markdown md.erb / xml - xml.erb ) Just let me know how do you see it |
@cs3b I love it ! The erb template is a clever addition. |
b75c14c to
191a3a0
Compare
|
Feature ready to review and merge @yjacquin |
yjacquin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @cs3b for the great work !
I think it's a great feature to add and we're near it being ready to get merged and added to the incoming 1.1.0.
We could also add this to the rails integration in the same fashion it has been done for tools and resources, wdyt ? It can also be done in a later iteration.
- Removed multi_message_prompt.rb as it's no longer needed after simplifying the messages API - The example was demonstrating the array-based API which has been removed in Task 3 - The inline_prompt.rb example now serves as the primary example for prompt functionality This change aligns the examples with the implementation changes made in PR yjacquin#21.
Key changes: - Added robust prompt registration and handling in Server class - Implemented base64 validation for image content to ensure MCP compliance - Simplified messages API to use only keyword arguments for better usability - Refactored code to follow DRY principles and improve maintainability - Updated tool_name method to follow the same pattern as prompt_name - Fixed unused parameters and linter warnings throughout the codebase - Added comprehensive test coverage for all new functionality - Added example prompts to demo files for easy adoption - Reverted version to 1.0.0 as requested by maintainer This implementation enables developers to create and register prompts that can generate messages with text, image, and resource content, following the MCP specification. The code is thoroughly tested and includes examples to demonstrate proper usage. All tasks from PR yjacquin#21 feedback have been addressed
9941bcf to
4ebfbf6
Compare
Key changes: - Added robust prompt registration and handling in Server class - Implemented base64 validation for image content to ensure MCP compliance - Simplified messages API to use only keyword arguments for better usability - Refactored code to follow DRY principles and improve maintainability - Updated tool_name method to follow the same pattern as prompt_name - Fixed unused parameters and linter warnings throughout the codebase - Added comprehensive test coverage for all new functionality - Added example prompts to demo files for easy adoption - Reverted version to 1.0.0 as requested by maintainer This implementation enables developers to create and register prompts that can generate messages with text, image, and resource content, following the MCP specification. The code is thoroughly tested and includes examples to demonstrate proper usage. All tasks from PR yjacquin#21 feedback have been addressed
4ebfbf6 to
46d5948
Compare
Key changes: - Added robust prompt registration and handling in Server class - Implemented base64 validation for image content to ensure MCP compliance - Simplified messages API to use only keyword arguments for better usability - Refactored code to follow DRY principles and improve maintainability - Updated tool_name method to follow the same pattern as prompt_name - Fixed unused parameters and linter warnings throughout the codebase - Added comprehensive test coverage for all new functionality - Added example prompts to demo files for easy adoption - Reverted version to 1.0.0 as requested by maintainer This implementation enables developers to create and register prompts that can generate messages with text, image, and resource content, following the MCP specification. The code is thoroughly tested and includes examples to demonstrate proper usage. All tasks from PR yjacquin#21 feedback have been addressed
46d5948 to
f1835b3
Compare
|
I've applied feedback and rebased against main. Keep the commits unsquashed so it will easier to review hope this time we will be able to merge :-) Waiting for your feedback @yjacquin |
|
Hi! I wasn't aware of this Pull Request, so yesterday I added support for prompts too. https://github.com/mariochavez/fast-mcp/tree/add-prompt-support If this PR is ready, other than the current merge conflicts, can we expect it to land anytime soon? |
|
|
||
| def call(code:, programming_language: nil) | ||
| assistant_template = File.read(File.join(File.dirname(__FILE__), 'templates/code_review_assistant.erb')) | ||
| user_template = File.read(File.join(File.dirname(__FILE__), 'templates/code_review_user.erb')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these files are not that big, perhaps it would be easy to read and use as inline ERB templates right in this file.
I'm not part of the team, so this is for @yjacquin to decide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, in case of prompt is short inline is recommended - this is just an example, that it is possible
README.md
Outdated
|
|
||
| # Define a prompt by inheriting from FastMcp::Prompt | ||
| class GreetingPrompt < FastMcp::Prompt | ||
| prompt_name 'greeting' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps this can be just "name"? prompt_name within FastMcp::Prompt sounds a bit repetitive.
Python https://gofastmcp.com/servers/prompts
and
node https://github.com/punkpeye/fastmcp/blob/main/src/examples/addition.ts#L170 version call it just "name".
/cc @yjacquin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Ruby, using :name as an attribute can be problematic in certain contexts due to naming conflicts.
Module.name # => "Module"
MyClass.name # => "MyClass"
some_object.name # can be defined implicitlyAdditionaly this the convention for this project see
Line 126 in 3d5a7e5
| def tool_name(name = nil) |
there was no feedback from the @yjacquin since beginning of April ( until he will say what next, i'm not working actively on this). Still prompts are a very powerful feature (especial when mcp is attached to ai agent)
|
Thank you for your work on this! I would love to see it merged into main soon. |
docs/prompts.md
Outdated
|
|
||
| arguments do | ||
| required(:document_type).filled(:string).description("Type of XML document") | ||
| required(:elements).array.description("Elements to include") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cs3b I think there must be a typo here
/home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/value.rb:62:in `call': wrong number of arguments (given 0, expected at least 1) (ArgumentError)
from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:63:in `block (2 levels) in value'
from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:208:in `append_macro'
from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:62:in `block in value'
from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:251:in `extract_type_spec'
from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:61:in `value'
from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/array.rb:22:in `block in value'
from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:251:in `extract_type_spec'
from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/array.rb:16:in `value'
from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:178:in `block in array'
from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:208:in `append_macro'
from /home/nfedyashev/.rbenv/versions/3.1.3/lib/ruby/gems/3.1.0/gems/dry-schema-1.14.1/lib/dry/schema/macros/dsl.rb:177:in `array'
from /home/nfedyashev/Projects/appfoo/app/resources/xml_prompt.rb:7:in `block in <class:XmlPrompt>'
.array(:hash). doesn't seem to work either:
Invalid arguments for prompt xml_generator: {"elements":["must be an array"],"attributes":["must be a hash"]}
Sending response: {:jsonrpc=>"2.0", :error=>{:code=>-32602, :message=>"{\"elements\":[\"must be an array\"],\"attributes\":[\"must be a hash\"]}"}, :id=>8}
|
@cs3b A few comments
https://github.com/yjacquin/fast-mcp?tab=readme-ov-file#-fast-ruby-on-rails-implementation
|
|
Other than a few comments above it works great! Thank you very much @cs3b |
|
Would love to see this merged -- let me know if I can help. |
5e25cca to
26b9871
Compare
dc7b377 to
ea034eb
Compare
|
Feature ready to review and merge @yjacquin |
31931f4 to
ee7326f
Compare
Implements full Model Context Protocol (MCP) prompts support per specification. Core Features: - New Prompt class with message creation and validation - Dry::Schema-based argument validation (same as tools) - ERB template support for structured prompt messages - Multiple message formats (hash, array, MessageBuilder pattern) - Support for text, image, and resource content types API Design: - MessageBuilder for fluent message construction - Flexible messages() method supporting multiple same-role messages - Base64 validation for image content compliance - Auto-naming from class names (CodeReviewPrompt → code_review) Feature Parity with Tools: - Authorization blocks for access control - Tags, metadata, and annotations support - Integration with ServerFiltering for dynamic filtering - Headers support for authorization context Server Integration: - Added prompts/list and prompts/get endpoints - Prompt registration methods (register_prompt, register_prompts) - Notification support for prompts list changes Rails Support: - Generator for creating new prompts (rails g fast_mcp:install) - ApplicationPrompt base class - Auto-loading from app/prompts directory - Sample prompt template with best practices Testing & Documentation: - 900+ lines of comprehensive tests - Example prompts (few-shot, inline, code review with templates) - Full documentation in docs/prompts.md - Rails integration guide updates Breaking Changes: None - purely additive feature
ee7326f to
f519045
Compare
|
@cs3b I haven't reviewed the latest code updates, but as a user I can confirm that it works fine. I'm currently using it as fork of fast-mcp before it gets merged. |

Updated: Prompts Feature with Main Branch Alignment
This PR has been rebased onto main and updated to align with current architecture.
Major Changes from Rebase:
1. ServerFiltering Integration
2. Feature Parity with Tools
3. Rails Integration
Testing:
Addresses Reviewer Feedback: